import { computed, reactive } from 'vue'
import { Form } from 'ant-design-vue';
import regular from '@/utils/regular'

const useForm = Form.useForm;

function useFormValidator(formState: any) {
  const rules = computed(() => {
    return {
      username: [{ required: true, message: '请输入手机号' }, { pattern: regular.regPhone, message: '请输入正确11位手机号' }],
      // password: [{ required: true, message: '请输入密码' }, { pattern: /^[\x21-\x7e]{6,14}$/, message: '6-14位密码' }],
      code: [{ required: true, message: '请输入验证码' }, { pattern: regular.regCaptcha, message: '请输入正确的验证码' }]
    }
  })
  const _formRules = reactive(rules)
  const { validate, validateInfos } = useForm(formState, _formRules, {
    onValidate: () => { },
  });
  return {
    // formRules,
    validateInfos,
    validate
  }
}

export {
  useFormValidator
}